#ifndef _TYPEC_STATE_MACHINE_H_
#define _TYPEC_STATE_MACHINE_H_

#include "typec_pd_config.h"

enum typec_vbus_level {
    TYPEC_VBUS_VSAFE0V = 1,         // < 0.8V
    TYPEC_VBUS_INVALID,             // > 0.8V
    TYPEC_VBUS_VALID,               // > 4V
    TYPEC_VBUS_LEVEL_MAX,
};

enum typec_cc_status {
    TYPEC_CC_DRP_TOGGLE = 1,

    TYPEC_CC_SRC_OPEN,
    TYPEC_CC_SRC_RA,
    TYPEC_CC_SRC_RD,

    TYPEC_CC_SNK_OPEN,
    TYPEC_CC_SNK_DEFAULT,
    TYPEC_CC_SNK_POWER_1A5,
    TYPEC_CC_SNK_POWER_3A,

    TYPEC_CC_STATUS_MAX,
};

enum typec_cc_orientation {
    TYPEC_CC1_COMM = 0,
    TYPEC_CC2_COMM,
};

enum typec_state_machine {
    TYPEC_DISABLED = 0,
    TYPEC_ERRORRECOVERY,

    TYPEC_UNATTACHED_SNK,
    TYPEC_UNATTACHED_SRC,

    TYPEC_ATTACHWAIT_SNK,
    TYPEC_ATTACHWAIT_SRC,

    TYPEC_ATTACHED_SNK,
    TYPEC_ATTACHED_SRC,

    TYPEC_TRY_SNK,
    TYPEC_TRY_WAIT_SRC,

    TYPEC_STATE_MAX,
};

enum typec_remote_rp_level {
    TYPEC_REMOTE_RP_DEFAULT = 0,
    TYPEC_REMOTE_RP_1A5,
    TYPEC_REMOTE_RP_3A,
};

bool typec_check_alert(void);
int typec_port_init(void);
void typec_pd_main_task(void);
int typec_state_transition_to(uint8_t new_state);

void typec_vbus_control(bool on, uint16_t out_mv, uint16_t out_ma);
void typec_ibus_control(uint16_t in_ma);

#endif

